package com.carleasoft.mps.adu.business.dict.controller;


import com.carleasoft.mps.adu.business.dict.bean.entity.SysDict;
import com.carleasoft.mps.adu.business.dict.bean.po.SysDictPo;
import com.carleasoft.mps.adu.business.dict.service.SysDictService;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.utils.IBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统字典表管理
 *
 * @author yanghao
 * @date 2021-12-17 17:27
 * @project mps
 */
@RestController
@RequestMapping(value = "/sysDict")
public class SysDictController {
    @Autowired
    private SysDictService sysDictService;


    /**
     * 分页查询字典列表
     *
     * @param sysDictPo
     * @param
     * @return
     */
    @PostMapping("/page")
    public R pageQuery(@RequestBody SysDictPo sysDictPo) {
        return R.ok(sysDictService.pageQuery(sysDictPo));
    }




    /**
     * 添加字典
     *
     * @param sysDict
     * @return
     */
    @PostMapping("/save")
    public R save(@RequestBody SysDict sysDict) {
        // 参数校验
        IBeanUtil.paramVerify("type", "dictValue");

        return R.ok(sysDictService.add(sysDict));

    }

    /**
     * 修改字典
     *
     * @param sysDict
     * @return
     */
    @PostMapping("/update")
    public R update(@RequestBody SysDict sysDict) {
        Boolean isOk = sysDictService.updateDict(sysDict);

        return R.ok(isOk);
    }

    @PostMapping("getByDictCodes")
    public R getByDictCodes(@RequestBody List<String> ids) {
        return R.ok(sysDictService.getByDictCodes(ids));
    }


    /**
     * 根据remark类型查字典列表
     *
     * @param sysDictPo
     * @return
     */
    @PostMapping("/listDict")
    public R listDict(@RequestBody SysDictPo sysDictPo) {
        List<SysDict> sysDict = sysDictService.doFindList(sysDictPo);
        return R.ok(sysDict);
    }

    /**
     * 根据id删除字典
     *
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public R delete(@PathVariable String id) {
        Boolean isOk = sysDictService.deleteDict(id);
        return R.ok(isOk);
    }


}
